SuperStrict

Import jmd.cfg

'Create a new instance and read in the file
Global cfg:TConfig=CreateConfig("config.ini")
ConfigRead(cfg) 'note, could have used autoRead parameter in the CreateConfig() function above

'Set up defaults, and load them in!
Local defaults:TMap = CreateMap()
defaults.insert("app_width","1024")
defaults.insert("app_height","768")
defaults.insert("title","Example TConfig usage")
defaults.insert("name","John Doe") 'this key/value pair was purposely left out of config.ini to show that the default works
ConfigSetDefaults(cfg,defaults)

'Get the information!
Print "Application Width: " + ConfigGetString(cfg,"app_width")
Print "Application Height: " + ConfigGetString(cfg,"app_height")
Print "Title: " + ConfigGetString(cfg,"title")
Print "Name: " + ConfigGetString(cfg,"name")

'Now lets make some changes!
ConfigUpdate(cfg,"name","Jane Doe",False) 'Since it doesn't exist, and the autoCreate parameter is false, nothing will happen!
'Notice that it doesn't work this time
Print "Name: " + ConfigGetString(cfg,"name")
ConfigUpdate(cfg,"name","Jane Doe",True) 'Now the autoCreate parameter is true! Note that this change won't permanently be saved to the file unless we call the ConfigWrite() function
'But now it does thanks to the autoCreate parameter being true!
Print "Name: " + ConfigGetString(cfg,"name")

'Now, lets try to get the value for a key that doesn't exist!
Print "Random number: " + ConfigGetString(cfg,"random")
'Lets add it!
ConfigAdd(cfg,"random",String(Rnd(1,10)))
Print "Random number: " + ConfigGetString(cfg,"random")

'Check to see if certain key/value pairs exist
If ConfigContains(cfg,"name")
	Print "name key found!"
Else
	Print "name key NOT found!"
EndIf

If ConfigContains(cfg,"address")
	Print "address key found!"
Else
	Print "address key NOT found!"
EndIf

'Uncomment below, and the changes will be saved to the file!
'ConfigWrite(cfg)